package org.UDP;

import java.io.IOException;
import java.net.*;
//UDP发送数据
public class SendMassage {
    public static void main(String[] args) throws IOException {
        //创建一个DatagramSocket对象
        DatagramSocket ds = new DatagramSocket();
        //打包数据
        String str = "hello";
        byte[] bytes = str.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 10086;

        //创建一个DatagramPacket对象
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, 10086);
        //发送数据
        ds.send(dp);
        //关闭DatagramSocket
        ds.close();
    }
}
